 $(document).ready(function() {
             //		权限判断
		if($.cookie('ID') == null){
			window.location.href="http://www.duoweish.com/crm/login.html";
		}
//		2，3号权限
		if($.cookie('Right') == 1){
			window.location.href="http://www.duoweish.com/crm/index.html";
		}
 	
			  var page_num = 0;		
             $(".select2").select2();
             $('#reservation').daterangepicker();
             
             Ajax(1);
            
             $('.dw_name').text($.cookie('Name'));
		 $('.dw_part').text($.cookie('Department'));
            function Ajax(curr){
            
			
				
            	$.ajax({
				headers:{
				    	Accept:"application/json;charset=utf-8"
				    },
					type:"get",
					url:"http://www.duoweish.com/apis/CstmApplyApprove/",
					data:{
                           page:curr||1,
					     	rows:8,
						  UserId:$.cookie('ID')
					},
					success:function(data){
							page_num = data[1];
							tableData(data);
							divePage(page_num,curr);
							
						}
				})
            	
            }
            
            function tableData(ret){
                    $('#table_body').empty();
                    
                    for(var i = 0;i < ret.length;i++){
                    	for (var j = 0;j<ret[i].length;j++) {
                    		
                    	if(ret[i][j][6]==undefined){
                    		ret[i][j][6]='此次更新没有备注';
                    	}
                        var tr = `<tr>
                                <td style="line-height:20px;">${ret[i][j][0]}</td>
                                <td style="line-height:20px;">${ret[i][j][1]}</td>
                                <td style="line-height:20px;">${ret[i][j][2]}</td>
                                <td style="line-height:20px;">${ret[i][j][3]}</td>
                                
                                <td  event="${ret[i][j][4]}">
                                   <button class="edit_btn check" index="1"><i style="font-size: 20px;" class="fa fa-pencil"></i></button>
                                	<span style="display:inline-block;width:20px;"></span>
                                	<button class="edit_btn check" index="0"><i style="font-size: 20px;" class="fa fa-trash-o"></i></button>
                                </td>
                               
                            </tr>`;
                        $('#table_body').append(tr);
                    }
                }
                   //渲染完页面判断权限是否允许删除操作
                   
                   
                   
            
                   
                   $(".check").click(function(){
                   	var self = $(this);
                   	var kind_statue = $(this).attr("index");
					
					
						 var iEvent = $(this).parent().attr('event');
							$.ajax({
								type:"get",
								url:"http://www.duoweish.com/apis/CstmApplyApproveSubmit/",
								
								data:{
									Id:iEvent,
									Kind:kind_statue
								},
								success:function(){
									if (data='success') {
  								         layer.msg('审批成功',{time:1000},function(){
  								         	self.parent().parent().remove();
  								         });
  								         
										} else{
			  									layer.msg('审批失败，请重试',{time:1000});
												}
									}
							})
				   })
             
                    
            }
           function divePage(page_num,curr){
            layui.use(['laypage', 'layer'], function(){
					 var laypage = layui.laypage
			  		,layer = layui.layer;
                     laypage.render({
						    elem: 'demo0'
						    ,count: page_num
						    ,curr:curr
						    ,jump: function(obj, first){
						    	   if(!first){
						                Ajax(obj.curr);
						               }
				        
						      		}
						   		});
					 })		
           }
          
          
     
           
})